/*
 * Copyright 2018 The JA-SIG Collaborative. All rights reserved.
 * distributed with thi file and available online at
 */
package com.lap.scp.admin.config;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

/**
 * <pre>
 * 密码加密方式
 * </pre>
 * 
 * @author 劳水生 Exp
 * @Date 2018年1月23日 下午4:01:06
 * @since 1.0
 */
public class CredentialsMatcher extends SimpleCredentialsMatcher {

	@Override
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
		UsernamePasswordToken authcToken = (UsernamePasswordToken) token;
		Object dapasswd = this.getCredentials(info);
		String encryptedPassWord = DigestUtils.md5Hex(String.valueOf(authcToken.getPassword()));
		if (dapasswd != null && encryptedPassWord != null) {
			return equals(encryptedPassWord, dapasswd);
		}
		return false;
	}

}
